package cloud.estate.estateManager.service.impl;

import cloud.estate.commons.bean.EstateManager;
import cloud.estate.commons.handler.exception.*;
import cloud.estate.commons.mapper.EstateManagerMapper;
import cloud.estate.commons.util.JsonResult;
import cloud.estate.commons.util.ResultTool;
import cloud.estate.estateManager.service.estateManagerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class estateManagerServiceImpl extends ServiceImpl<EstateManagerMapper,EstateManager> implements estateManagerService {
    @Override
    public JsonResult addOneEstateManager(EstateManager estateManager){
        try {
            boolean save = save(estateManager);
            if (save){
                return  ResultTool.success("添加成功");
            }
            return ResultTool.fail(501,"添加失败");
        } catch (Exception e) {
            throw new AddOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult deleteOneEstateManager(String id){
        try {
            boolean removeById = removeById(id);
            if (removeById){
                return  ResultTool.success("删除成功");
            }
            return ResultTool.fail(501,"删除失败");
        } catch (Exception e) {
            throw new DealOneByIdException(e.getMessage());
        }
    }
    @Override
    public JsonResult updateOneEstateManager(EstateManager estateManager){
        try {
            boolean updateById = updateById(estateManager);
            if (updateById){
                return  ResultTool.success("更新成功");
            }
            return ResultTool.fail(501,"更新失败");
        } catch (Exception e) {
            throw new UpdateOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult getOneEstateManager(String id){
        try {
            EstateManager estateManager = getById(id);
            if (estateManager != null){
                return  ResultTool.success(estateManager);
            }
            return ResultTool.fail(501,"查询失败");
        } catch (Exception e) {
            throw new FindOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult listAllEstateManager(){
        try {
            List<EstateManager> list = list();
            if (list != null){
                return  ResultTool.success(list);
            }
            return  ResultTool.success(list());
        } catch (Exception e) {
            throw  new FindAllException(e.getMessage());
        }
    }
}
